﻿@using IterationLife.Extensions.EasyUI.GridColumns
@using IterationLife.FootballTeaching.Queries
@using Util.Ui
@model IterationLife.PlatformBackEnd.AppServices.Dtos.FootballTeachings.CourseCategoryDto
@{
    var x = @Html.EasyUi();
}
<script type="text/javascript">
    var dialog_courseCategory_Choice = function () {
        var checkedRows = $.easyui.getGrid("grid_dialog_courseCategory").datagrid("getChecked");
        if (checkedRows.length === 0) {
            $.easyui.warn("最少选择一个分类");
            return;
        }
        var show = '';

        var getExcludeIds = function () {
            var onclick = $("#dialogButtonsBtn_courseCategory").attr("onclick");
            var excludeIdsStr = onclick.match(/excludeIds=(\S*)'/)[1];
            if (!excludeIdsStr)
                return [];
            return excludeIdsStr.split(',');
        }
        var excludeIds = getExcludeIds();

        for (var i = 0; i < checkedRows.length; i++) {
            var courseCategory_option_gethtml = function (number, courseCategory) {
                var li = '<div onclick="delete_courseCategory(this,\'' + courseCategory.Id + '\')">';
                li += '<input type="text" name="CourseCategories[' + number + '].Id" value="' + courseCategory.Id + '" hidden/>';
                li += '<input type="text" name="CourseCategories[' + number + '].Name" value="' + courseCategory.Name + '" hidden/>';
                li += '<span class="course-option">' + courseCategory.Name + '</span>';
                li += '</div>';
                return li;
            }
            show += courseCategory_option_gethtml(excludeIds.length, checkedRows[i]);
            excludeIds.push(checkedRows[i].Id);
        }
        $("#dialogButtonsBtn_courseCategory").attr("onclick", "$.easyui.dialog({ title: '选择分类', buttons: 'dialogButtons_courseCategory', url: '/FootballTeachings/CourseCategory/DialogIndex?excludeIds=" + excludeIds + "' })");
        $("#dd_courseCategorise_data").append(show);
        $.easyui.closeDialog();
    }
</script>
@using (x.Layout(true).Begin())
{
    using (x.LayoutRegion().Center().Begin())
    {
        @Html.Partial("Dialogs/QueryForm", new CourseCategoryQuery { ExcludeIds = Model.ExcludeIds, Enabled = true })
        @(x.Grid("grid_dialog_courseCategory").Sort("SortId", false).Toolbar("divQuery_dialog_courseCategory").Url($"/FootballTeachings/CourseCategory/PagerQuery?ExcludeIds={Model.ExcludeIds}")
              .ShowEditDialogByDblClick().Menu().FitColumns().Fit()
              .Columns(
                  x.GridColumn(t => t.Id).CheckBox(),
                  x.GridColumn(t => t.Code, 100),
                  x.GridColumn(t => t.Name, 100),
                  x.GridColumn(t => t.Banner, 100).AttachmentPreview(),
                  x.GridColumn(t => t.SortId, 100),
                  x.GridColumn(t => t.CreationTime, 120)
              ).Pagination(true, 10)
        )
    }
}
<div id="dialogButtons_courseCategory">
    @x.Button("保 存").Icon("icon-ok").Width(90).Click("dialog_courseCategory_Choice()")
    @x.DialogButton("关 闭").Icon("icon-cancel").Width(90).CloseDialog()
</div>